package com.example.micro.es.api.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * es配置类，注入基本步骤
 * 1》找对应类
 * 2》放入Spring中
 * 3》如果是Springboot 就先分析源码
 *
 * @author Code Farmer
 * @create 2020/9/27 3:12 下午
 */
@Configuration
public class ElasticSearchClientConfig {

    //类似于<bean id="restHighLevelClient" class="RestHighLevelClient"/>
    @Bean
    public RestHighLevelClient restHighLevelClient() {
        return new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("127.0.0.1", 9200, "http")
                )
        );
    }

}
